package com.example.taluo.controller;

import com.example.taluo.config.CurrentUser;
import com.example.taluo.entity.User;
import com.example.taluo.entity.dto.ResponseDO;
import com.example.taluo.entity.dto.gamedto.UserRanking;
import com.example.taluo.service.LeaderBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/leaderboard")
public class LeaderBoardController {
    @Autowired
    private LeaderBoardService leaderBoardService;

    /**
     * 获取排行榜数据
     * @param page 页码
     * @param size 每页大小
     * @return 排行榜分页数据
     */
    @GetMapping
    public ResponseDO getLeaderboard(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int size) {
        return ResponseDO.success(leaderBoardService.getLeaderboard(page, size));
    }

    @GetMapping("/my-ranking")
    public ResponseDO getMyRanking(@CurrentUser User user) {
        return ResponseDO.success(leaderBoardService.getUserRanking(user.getId()));
    }
}
